<!DOCTYPE HTML>
<html lang="en">
<head>
<title>GetKeyName() / GetKeyVK() / GetKeySC() - Syntax &amp; Usage | AutoHotkey</title>
<meta name="description" content="The GetKeyName, GetKeyVK and GetKeySC functions retrieve the name/text, virtual key code or scan code of a key." />
<meta name="ahk:equiv-v2" content="commands/GetKeyName.htm" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>GetKeyName() / GetKeyVK() / GetKeySC() <span class="ver">[v1.1.01+]</span></h1>

<p>Retrieves the name/text, virtual key code or scan code of a key.</p>

<pre class="Syntax">
String := <span class="func">GetKeyName</span>(Key)
Number := <span class="func">GetKeyVK</span>(Key)
Number := <span class="func">GetKeySC</span>(Key)
</pre>
<h2>Parameters</h2>
<dl>

  <dt>Key</dt>
  <dd><p>A VK or SC code, such as <code>"vkA2"</code> or <code>"sc01D"</code>, a combination of both, or a <a href="../KeyList.htm">key name</a>. For example, both <code>GetKeyName("vk1B")</code> and <code>GetKeyName("Esc")</code> return <code>Escape</code>, while <code>GetKeyVK("Esc")</code> returns <code>27</code>. Note that VK and SC codes must be in hexadecimal. To convert a decimal number to the appropriate format, use <code><a href="Format.htm">Format</a>("vk{:x}", vk_code)</code> or <code>Format("sc{:x}", sc_code)</code>.</p></dd>

</dl>

<h2>Return Value</h2>
<p>These functions return a name, virtual key code or scan code of <em>Key</em>.</p>

<h2>Related</h2>
<p><a href="GetKeyState.htm">GetKeyState()</a>, <a href="../KeyList.htm">Key List</a>, <a href="Format.htm">Format()</a></p>
<h2>Examples</h2>
<div class="ex" id="ExBasic">
<p><a href="#ExBasic">#1</a>: Show information for a specific key.</p>
<pre>key  := "LWin" <em>; Any key can be used here.</em>

name := GetKeyName(key)
vk   := GetKeyVK(key)
sc   := GetKeySC(key)

MsgBox, % Format("Name:`t{}`nVK:`t{:X}`nSC:`t{:X}", name, vk, sc)</pre>
</div>

</body>
</html>
